#pragma once
#include <string>
#include <unordered_map>
#include <chrono>
#include <limits>
#include <map>

class Timer {
public:
    void start();
    void end();
    void printSummary(const std::string& name) const;
    double getLastDuration() const;

private:
    std::chrono::high_resolution_clock::time_point start_time_;
    double total_time_ = 0.0;
    double min_time_ = std::numeric_limits<double>::max();
    double max_time_ = 0.0;
    double last_duration_ = 0.0;  
    int count_ = 0;
};

class TimerManager {
public:
    void start(const std::string& name);
    void end(const std::string& name);
    void printAllSummaries() const;
    double getLastDuration(const std::string& name) const;  
    static TimerManager& getInstance();

private:
    std::unordered_map<std::string, Timer> timers_;
};